﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenLS.Spreadsheet;
using OpenLS.Spreadsheet.UI.Interfaces;

namespace Modularity
{
    public class ModuleViewModel<T> : INotifyPropertyChanged where T : IDataModule, new()
    {
        private OpenLS.Spreadsheet.Table _CurrentTable;
        public OpenLS.Spreadsheet.Table CurrentTable
        {
            set { _CurrentTable = value; }
        }

        private T _CurrentDataModule;
        public T CurrentDataModule
        {
            get
            {
                if (_CurrentDataModule == null)
                {
                    _CurrentDataModule = new T();
                }
                return _CurrentDataModule;
            }
        }


        private string _tableName;
        public string TableName
        {
            get { return _tableName; }
            set
            {
                _tableName = value;
                OnPropertyChanged("TableName");
            }
        }

        private string _tableComment;
        public string TableComment
        {
            get { return _tableComment; }
            set
            {
                _tableComment = value;
                OnPropertyChanged("TableComment");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;


        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

    }
}
